#ifndef BESIERSPLINE_H
#define BESIERSPLINE_H

#include <QObject>
#include <QWidget>
#include<QLabel>
#include<Eigen/Core>
#include<Eigen/Dense>
#include<vector>

using V2f = Eigen::Vector2f;
using List2f = std::vector<V2f>;

class besierspline : public QLabel
{
    Q_OBJECT
public:
    explicit besierspline(QWidget *parent = nullptr);
    void paintEvent(QPaintEvent *);
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);
    void mouseMoveEvent(QMouseEvent *ev);
    void mousePressEvent(QMouseEvent *ev);
    void mouseReleaseEvent(QMouseEvent *ev);

    int setControlPoints(const List2f &A);
    void chaikinSubdivide(int iter);
    void cubicSubdivide(int iter);
    void fittingSubdivide(int iter);
signals:
    void select(besierspline *);
private:
    int drag;
    int state = 0; // 0 normal, 1 new, 2 edit 3 delete
    QPoint lastPos;

    List2f controlPoints;
    List2f showPoints;
    // 根据坐标点更新位置和大小
    void updateBox();
};

#endif // BESIERSPLINE_H
